package main

import (
	"backend/Manager"
	"fmt"
	"log"
	"os"
	"path/filepath"
	"runtime"
	"strings"
	"time"
)

func GetCurrentPath() (currentDir string, ok bool) {
	dir, err := os.Getwd()
	if err != nil {
		log.Println("Error of os.GetWd", err)
		return "", false
	}
	path, err := filepath.Abs(dir)
	if err != nil {
		log.Println("Error of filepath.Abs", err)
		return path, false
	}

	var programPath string
	_, f, _, ok := runtime.Caller(0)
	if ok {
		programPath = filepath.Dir(f)
	}

	execName := os.Args[0]
	OK := strings.Contains(execName, "_go_build_")
	if OK {
		return programPath, true
	}
	return path, true
}

func main() {
	fmt.Println("\n执行中，请稍后 ......")

	dir, ok := GetCurrentPath()
	if !ok {
		fmt.Println("GetCurrentPath failed")
		return
	}

	localFolder := filepath.Join(dir, "dist")

	//fmt.Println("localFolder:", localFolder)

	Manager.RsyncLocalFold(localFolder, false)

	fmt.Println("\n----------执行结束 -----------")

	time.Sleep(5 * time.Second)
}
